/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShAccountMessageDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShAccountMessageService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShAccountMessage;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShAccountMessageService 实现类
 * @author KongXiangyu
 * @since 2015-09-07
 */
@Service("shAccountMessageService")
public class ShAccountMessageServiceImpl extends BaseServiceImpl<ShAccountMessage, Long> implements ShAccountMessageService {

    @Resource
    private ShAccountMessageDao shAccountMessageDao;

    public BaseDao<ShAccountMessage, Long> getDao() {
        return shAccountMessageDao;
    }

	@Override
	public DataGrid quetyDataGrid(ShAccountMessage queryAccountMessage,
			PageHelper page) {
		DataGrid grid = new DataGrid();

		if (!StringUtils.isBlank(page.getOrder())) {
			queryAccountMessage.setOrderFieldType(page.getOrder());
		}
		if (!StringUtils.isBlank(page.getSort())) {
			queryAccountMessage.setOrderField(page.getSort());
		}

		int startIndex = (page.getPage() - 1) * page.getRows();
		int endIndex = page.getPage() * page.getRows();
		Long count = shAccountMessageDao.queryShAccountMessagesCount(queryAccountMessage);
		grid.setTotal(count);

		if (grid.getTotal() > 0 && grid.getTotal() > startIndex) {
			queryAccountMessage.setStartIndex(startIndex);
			queryAccountMessage.setEndIndex(endIndex);
			List<ShAccountMessage> rows = shAccountMessageDao.queryShAccountMessages(queryAccountMessage);
			grid.setRows(rows);
		}

		return grid;
	}

	@Override
	public List<ShAccountMessage> queryAccountMessageList(
			ShAccountMessage accountMessage) {
		return shAccountMessageDao.queryShAccountMessages(accountMessage);
	}

	@Override
	public int count(ShAccountMessage accountMessage) {
		return shAccountMessageDao.selectEntryListCount(accountMessage);
	}

	@Override
	public int batchUpdate(ShAccountMessage accountMessage) {
		return shAccountMessageDao.batchUpdate(accountMessage);
	}

}